package com.library.system.controller;

import com.library.logging.annotation.LogSys;
import com.library.system.modules.emailconfig.vo.EmailConfigVO;
import com.library.system.modules.emailconfig.bo.EmailConfigInsert;
import com.library.system.modules.emailconfig.bo.EmailConfigUpdate;
import com.library.system.modules.emailconfig.service.EmailConfigService;
import org.springframework.web.bind.annotation.*;
import com.library.common.response.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;

import java.util.List;
import java.util.Objects;


/**
 * @Author xyh
 * @Desc 邮箱配置(EmailConfig)表控制层
 * @Date 2023-09-24 16:14:28
 */

@RestController
@RequestMapping("emailconfig")
public class EmailConfigController {

    @Resource
    private EmailConfigService emailConfigService;


    /**
     * 分页查询列表
     *
     * @return 数据
     */
    @LogSys(value = "邮箱配置分页查询列表")
    @GetMapping("/list")
    public Result<List<EmailConfigVO>> list() {
        List<EmailConfigVO> voList = emailConfigService.emailConfigList();
        return Result.success(voList);
    }

    /**
     * 根据ID获取数据
     *
     * @return 单个邮箱配置数据
     */
    @LogSys(value = "单个邮箱配置数据")
    @PostMapping("/queryById/{id}")
    public Result<EmailConfigVO> queryById(@PathVariable("id") Integer id) {
        return Result.success(emailConfigService.queryById(id));
    }


    /**
     * 添加邮箱配置
     *
     * @return 新增邮箱配置数据
     */
    @LogSys(value = "新增邮箱配置数据")
    @PostMapping("/insert")
    public Result insert(@Valid @RequestBody EmailConfigInsert param) {
        emailConfigService.insert(param);
        return Result.success();
    }


    /**
     * 编辑邮箱配置
     *
     * @return 编辑邮箱配置数据
     */
    @LogSys(value = "编辑邮箱配置数据")
    @PutMapping("/update")
    public Result update(@Valid @RequestBody EmailConfigUpdate param) {
        if (Objects.isNull(param.getId())) {
            return Result.error("ID不能为空");
        }
        emailConfigService.update(param);
        return Result.success();
    }

    /**
     * 删除邮箱配置
     *
     * @return 删除邮箱配置数据
     */
    @LogSys(value = "删除邮箱配置数据")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable("id") Integer id) {
        emailConfigService.deleteById(id);
        return Result.success();
    }
}
